              package com.java.diagnostics.visualizer.displayer.html;
              
              import com.java.diagnostics.visualizer.coredisplayers.util.Messages;
              import com.java.diagnostics.visualizer.data.AggregateData;
              import com.java.diagnostics.visualizer.data.DataSet;
              import com.java.diagnostics.visualizer.data.TupleData;
              import com.java.diagnostics.visualizer.data.Variant;
              import com.java.diagnostics.visualizer.data.axes.Axis;
              import com.java.diagnostics.visualizer.data.axes.DataAxis;
              import com.java.diagnostics.visualizer.data.axes.XDataAxis;
              import com.java.diagnostics.visualizer.data.axes.YDataAxis;
              import com.java.diagnostics.visualizer.data.ids.ID;
              import com.java.diagnostics.visualizer.display.DataDisplayer;
import com.java.diagnostics.visualizer.displayer.plot.SWTPlotDataDisplayer;
              import com.java.diagnostics.visualizer.exceptions.GCAndMemoryVisualizerException;
              import com.java.diagnostics.visualizer.impl.extensions.DisplayerRegistry;
              import com.java.diagnostics.visualizer.impl.properties.OutputPropertiesImpl;
              import com.java.diagnostics.visualizer.properties.IDsToDisplayProperties;
              import com.java.diagnostics.visualizer.properties.OutputProperties;

              import java.io.BufferedWriter;
              import java.io.File;
              import java.io.IOException;
              import java.util.logging.Level;
              import java.util.logging.Logger;
              import java.util.regex.Matcher;
              import java.util.regex.Pattern;

              import org.eclipse.core.runtime.CoreException;
              import org.eclipse.core.runtime.IConfigurationElement;
              import org.eclipse.swt.graphics.Rectangle;
              import org.eclipse.swt.widgets.Canvas;
              import org.eclipse.swt.widgets.Composite;
              import org.eclipse.swt.widgets.Display;
              import org.eclipse.swt.widgets.Shell;
              
              public abstract class TupleDataWriter extends DataWriter
              {
                private static final String ALT = "\" alt=\"";
                private static final String IMG_OPEN = "<img src=\"";
                protected static final String NEWLINE = System.getProperty("line.separator");
              
                private static final String BR = "<br/>" + NEWLINE;
                private static final String CANVAS = "canvas";
                protected static final String UNIT_LABEL_FORMAT = "{0} ({1})";
                private static final Pattern FILE_NAME_SEARCH_REPLACE_REGEX = Pattern.compile("[ \\.#:,\\?\\*/]");
                private static final int DEFAULT_WIDTH = 400;
                protected OutputProperties outputProperties;
                private File directory;
                protected DataAxis axis;
                static int uniqueImageIndex = 0;
              
                protected TupleDataWriter(DataSet dataSet, OutputProperties outputProperties, AggregateData representativeData, BufferedWriter buffer, ID id, File directory)
                {
                  super(dataSet, id, representativeData, buffer);
                  this.outputProperties = outputProperties;
                  this.directory = directory;
                  TupleData data = representativeData.getTupleData(id);
                  if (data != null)
                    this.axis = data.getYAxis();
                }
              
                protected abstract void writeColumnHeadings()
                  throws IOException;
              
                protected abstract void addRow(TupleData paramTupleData)
                  throws IOException;
              
                public void writeData() throws IOException
                {
                  boolean showTupleStats = this.preferencesHelper.getShowTupleStats();
              
                  this.usingTable = true;
                  addDataHeading();
              
                  if (showTupleStats) {
                    openTable();
              
                    if (this.usingTable) {
                      writeColumnHeadings();
                    }
              
                    Variant[] variants = this.dataSet.getVariants();
                    for (int i = 0; i < variants.length; i++)
                    {
                      openRow();
                      Variant variant = variants[i];
              
                      if (this.dataSet.getVariants().length > 1) {
                        addTableHeader(variant.getLabel(), 1);
                      }
                      TupleData data = variant.getTupleData(this.id);
                      addRow(data);
              
                      closeRow();
                      this.oddRow = (!this.oddRow);
                    }
                    closeTable();
                  }
                  createImage(this.dataSet, this.outputProperties, this.id);
                }
              
                protected void createImage(DataSet dataSet, OutputProperties originalProperties, ID id)
                {
	             // deleted by wenguang.huang 
                 // DisplayerRegistry registry = DisplayerRegistry.getInstance();
                 // IConfigurationElement[] displayers = registry
                 //   .findExtensionsByOutputType("canvas");
              
                  OutputProperties displayerProperties = new OutputPropertiesImpl(dataSet);
              
                  displayerProperties.getTupleFieldsToDisplay().disableNotifications();
                  displayerProperties.getTupleFieldsToDisplay().removeAllIDs();
                  displayerProperties.getTupleFieldsToDisplay().addID(id);
              
                  Axis xAxis = this.representativeData.getTupleData(id).getXAxis().getAxis();
                  String xUnits = this.outputProperties.getUnits(xAxis);
                  displayerProperties.setUnits(xAxis, xUnits);
                  Axis yAxis = this.representativeData.getTupleData(id).getYAxis().getAxis();
                  String yUnits = this.outputProperties.getUnits(yAxis);
                  displayerProperties.setUnits(yAxis, yUnits);
              
                  Display display = Display.getCurrent();
                  boolean shellNeedsDisposing = false; 
                  Composite parent = (Composite)this.outputProperties.getDisplayerProperties(HTMLReportDisplayer.class.getName());
                    
                  if (parent == null) {
                    parent = new Shell(display);
                    if ((this.outputProperties.getSaveWidth() != null) && 
                      (this.outputProperties.getSaveHeight() != null)) {
                      int parentWidth = this.outputProperties.getSaveWidth().intValue();
                      int parentHeight = this.outputProperties.getSaveHeight().intValue();
                      parent.setSize(parentWidth, parentHeight);
                    }
                    shellNeedsDisposing = true;
                  }
             // deleted by wenguang.huang 
             // for (int i = 0; i < displayers.length; i++) {
                    Canvas canvas = null;
                    try
                    {
	                  // deleted by wenguang.huang 
                      //IConfigurationElement displayerConfig = displayers[i];
              
                      //String displayerName = displayerConfig
                      //  .getAttribute("class");
                      //added by wenguang.huang 
	                  String displayerName ="strname";
                      //added end by wenguang.huang 


                      canvas = new Canvas(parent, 0);
                  
                      int xsize = (int)(parent.getBounds().width * 0.7D);
                      if (xsize == 0) {
                        xsize = 400;
                      }
                      int ysize = (int)(xsize * 0.75D);
              
                      canvas.setBounds(0, 0, xsize, ysize);
                      displayerProperties.setDisplayerProperties(displayerName, 
                        canvas);
                      
                  //added by wenguang.huang 
                  SWTPlotDataDisplayer displayer = new SWTPlotDataDisplayer();
                  DataDisplayer tupleDisplayer = (DataDisplayer)displayer;
				  //added end by wenguang.huang 

                     // deleted by wenguang.huang 
                     // DataDisplayer tupleDisplayer = (DataDisplayer)displayerConfig
                     //   .createExecutableExtension("class");
              
                      tupleDisplayer.display(dataSet, displayerProperties);
              
                      String extension = tupleDisplayer.getDefaultFileSaveExtension();
                      String shortName = generateFileName(id, displayerName, extension); 
                       
                      File file = new File(this.directory, shortName);
                      String filename = file.getName();
              
                      tupleDisplayer.save(file.getAbsolutePath());
                      this.buffer.write(BR);
                      this.buffer.write("<img src=\"");
                      this.buffer.write(filename);
                      this.buffer.write("\" alt=\"");
                      this.buffer
                        .write(
                        Messages.getString(
                        "HTMLReportDisplayer.alt.image.text", new Object[] { this.representativeData.getTupleData(id).getDisplayName(), displayerName }));
                      this.buffer.write("\">");
                      this.buffer.write(BR);
                    } catch (GCAndMemoryVisualizerException e) {
                      TRACE.log(Level.WARNING, 
                        Messages.getString("HTMLReportDisplayer.caught.exception"), e);
                    }
                // deleted by wenguang.huang 
                //  catch (CoreException e) {
                    //  TRACE.log(Level.WARNING, 
                    //    Messages.getString("HTMLReportDisplayer.caught.exception"), e);
                    //}
                    catch (IOException e) {
                      TRACE.log(Level.WARNING, 
                        Messages.getString("HTMLReportDisplayer.caught.exception"), e);
                    } finally {
                      if (canvas != null) {
                        canvas.dispose();
                      }
                    }
              
              // deleted by wenguang.huang 
              //          }
              
                  if (shellNeedsDisposing)
                    parent.dispose();
                }
              
                protected String generateFileName(ID id, String displayerName, String suffix)
                {
                  String name = this.representativeData.getTupleData(id).getLabel() + 
                    "_" + uniqueImageIndex++;
                  Matcher expression = FILE_NAME_SEARCH_REPLACE_REGEX.matcher(name);
                  boolean matches = expression.find();
                  if (matches) {
                    return expression.replaceAll("") + suffix;
                  }
                  return name + suffix;
                }
              }

